package com.felix.test;

import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class ChatXml {
	public static int showMsg(String xml){
		int pmk=0;
		try {
			Document doc=DocumentHelper.parseText(xml);
			Element rootElt = doc.getRootElement(); // 获取根节点
			String kk=rootElt.attributeValue("pmkey");
			if (kk!=null&&!"".equals(kk)) {
				pmk=Integer.parseInt(kk);
			}
			Iterator iterss = rootElt.elementIterator("body"); ///获取根节点下的子节点body
			while(iterss.hasNext()){
				Element recordEless = (Element) iterss.next();
				Iterator sub = recordEless.elementIterator("list");
				if (sub.hasNext()) {
					Element list = (Element) sub.next();
					if (!list.isTextOnly()) {
						System.out.println("您有如下新消息：");
						System.out.println(list.asXML());
					}

				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return pmk;
	}
	
	public static int afterSend(String xml){
		int pmk=0;
		try {
			Document doc=DocumentHelper.parseText(xml);
			Element rootElt = doc.getRootElement(); // 获取根节点
			String kk=rootElt.attributeValue("pmkey");
			if (kk!=null&&!"".equals(kk)) {
				pmk=Integer.parseInt(kk);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return pmk;
	}

}
